<?php
/**
 * Created by PhpStorm.
 * User: dungnt13
 * Date: 11/22/14
 * Time: 12:05 PM
 */

class Tag extends Eloquent
{
    use SoftDeletingTrait;

    protected $dates = ['deleted_at'];

    public function lyrics()
    {
        return $this->belongsToMany('Lyric', 'taggable', 'tag_id', 'lyric_id');
    }

    public function lesson()
    {
        return $this->belongsToMany('Lesson', 'taggable', 'tag_id', 'lesson_id');
    }

    public function videos()
    {
        return $this->belongsToMany('Video', 'taggable', 'tag_id', 'video_id');
    }

    public static function Check($title)
    {
        $tag = Tag::where('title', '=', $title)->first();
        if (is_null($tag)) {
            $tag = new Tag();
            $tag->title = $title;
            $tag->slug = Str::slug($title);
            $tag->save();
            return $tag->id;
        }
        return $tag->id;
    }

} 